import logging
from logging.handlers import TimedRotatingFileHandler

class MyLoger():
    def __init__(self):
        self.log_level = logging.DEBUG
        self.log_format = logging.Formatter('%(asctime)s--%(filename)s[line:%(lineno)d]--%(levelname)s:%(message)s', '%Y/%m/%d-%H:%M:%S')
        self.log_path = r"./dependence/TestLog.log"

        self.root_log = logging.getLogger("RootLog")
        self.root_log.propagate=False
        self.root_log.setLevel(self.log_level)
        self.root_log.handlers = []
        self.fhandle = TimedRotatingFileHandler(self.log_path, when="D")
        self.fhandle.setLevel(self.log_level)
        self.fhandle.setFormatter(self.log_format)
        self.root_log.addHandler(self.fhandle)

    def get_logger(self, name):
        return logging.getLogger("RootLog." + name)


# class MyLoger():
#     def __init__(self,name=None):
#         self.log_level = logging.DEBUG
#         self.log_format = logging.Formatter('%(asctime)s--%(filename)s[line:%(lineno)d]--%(levelname)s:%(message)s', '%Y/%m/%d-%H:%M:%S')
#         self.log_path = r"./dependence/TestLog.log"
#
#         self.root_log = logging.getLogger(name)
#         self.root_log.propagate=False
#         self.root_log.setLevel(self.log_level)
#         self.fhandle = TimedRotatingFileHandler(self.log_path, when="D")
#         self.fhandle.setLevel(self.log_level)
#         self.fhandle.setFormatter(self.log_format)
#         self.root_log.addHandler(self.fhandle)
#
#     def get_logger(self):
#         return logging.getLogger()

# if __name__ == '__main__':
#     log = MyLoger().get_logger("test")
#     log.error("Asd")